package sca;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class ScaProviderApplication {

    private static final Logger log=
            LoggerFactory.getLogger(ScaProviderApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(ScaProviderApplication.class, args);
    }


    @RefreshScope
    @RestController
    public class ProviderController {
        @Value("${server.port:没有port值}")
        private String server;

        @Value("${logging.level.sca:error}")//":"后面为默认值
        private String logLevel;

        @Value("${server.tomcat.threads.max:50}")
        private Integer maxThread;

        @Value("${page.pageNum:4}")
        private Integer pageNum;

        @GetMapping("/provider/echo/{msg}")
        public String doEcho(@PathVariable String msg) {
            if (msg == null || msg.length() < 3){
                System.out.println("sout----参数非法");
                throw new RuntimeException("参数非法");
            }
            return server+" say: Hello， " + msg;
        }

        @GetMapping("/provider/logLevel")
        public String doGetLevel(){
            log.trace("==log.trace==");
            log.debug("==log.debug==");
            log.warn("==log.warn==");
            log.info("==log.info==");
            log.error("==log.error==");
            return "the level of this is: "+logLevel;
        }

        @GetMapping("/Provider/getMaxThread")
        public String getMaxThread(){
            log.info("Just lick it");
            return "the max Threads of this is: "+maxThread;
        }

        @GetMapping("/provider/getPage")
        public String getPage(){
            log.info("Just lick it");
            return "the pageNum of this is: "+pageNum;
        }
    }

}